package com.aifund.app.hander;

import com.aifund.app.enums.MqQueueEnum;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

public class MqMsgHander {

    //这里要主要哦一定要自定义containerFactory不然会抛异常unknown delivery tag 1
    @RabbitListener(queues = "NewNewApiDirectQueue",containerFactory = "rabbitListenerContainerFactory")
    public void processMessage(Channel channel, Message message) throws IOException {
        try{
            //签收消息
            System.out.println("---签收消息");
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        }catch (Exception e){
            System.out.println("---签收消息异常");
            //处理抛出异常，如果重新把消息放回队列则requeue设置为true否则设置为false
//            channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
        }

    }
}
